package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("AdminShopStatusController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "店铺状态接口")
public class ShopStatusController {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("设置营业状态")
    @PutMapping("/{status}")
    public Result<String> ShopSetStatus(@PathVariable Integer status){
        log.info("设置营业状态为:{}",status==1?"营业中":"打烊中");
        redisTemplate.opsForValue().set("status",status);
        return Result.success("设置成功");
    }

    @ApiOperation("查询营业状态")
    @GetMapping("/status")
    public Result<Integer> ShopGetStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get("status");
        log.info("查询到营业状态为：{}",status==1?"营业中":"打烊中");
        return Result.success(status);
    }
}
